GetDCSystemTime

Gets the time stamp of the selected Sync0's signal of the distributed clock (DC).

Syntax

KsError GetDCSystemTime(
     DcCycle Cycle,
     DWORD64* Time
);

Parameters

Cycle: the DC time you want to acquire. See the DcCycle type.

Time: pointer to the time of the distributed clock.

Return value

If the function succeeds, it returns errNoError, otherwise an error code. For more information about the error code, see the KsError list.

Usable EtherCAT states

ecatOP

Example

Copy
/*
*    This code snippet demonstrates how to use GetDCSystemTime() to operate
*    Beckhoff EL2252 2-channel digital output terminal with time stamp.
*    For more information, please refer to the device user manual.
*/
const int EL2252 = 2; // This value depends on the actual index in your network
DWORD64 dcTime = 0;
DWORD64 dcStartTime = 0;

nRet = GetDCSystemTime(DcCycle::dcCurrent, &dcTime);
// Set the output to true
WriteOutputBit(EL2252, 72, true);
WriteOutputBit(EL2252, 74, true);
// Set Activate byte to 0
WriteOutputByte(EL2252, 0, 0);
// Calculate the start time
dcStartTime = dcTime + 500000000;
// Write the start time
WriteOutputDWord(EL2252, 1, (dcStartTime & 0xFFFFFFFF));
WriteOutputDWord(EL2252, 5, (dcStartTime & 0xFFFFFFFF00000000ULL) >> 32);
// Set Activate byte to 3 in the following cycle
Sleep(1);
WriteOutputByte(EL2252, 0, 3);

Sleep(2000);

nRet = GetDCSystemTime(DcCycle::dcCurrent, &dcTime);
// Repeat the routine and set the output to false
WriteOutputBit(EL2252, 72, false);
WriteOutputBit(EL2252, 74, false);
WriteOutputByte(EL2252, 0, 0);
dcStartTime = dcTime + 500000000;
WriteOutputDWord(EL2252, 1, (dcStartTime & 0xFFFFFFFF));
WriteOutputDWord(EL2252, 5, (dcStartTime & 0xFFFFFFFF00000000ULL) >> 32);
Sleep(1);
WriteOutputByte(EL2252, 0, 3);

Requirements

  RT Win32
Minimum supported version 4.0 4.0
Header ksapi.h ksapi.h
Library KsApi_Rtss.lib KsApi.lib

See also

ConfigureDc